package com.qf.utils;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * created by 赵文韬 on 2022/3/14 19:58
 */
public class MD5Utils {
    private static String zifu="jkldshhilke809347lksjdfJDFKLS";
    private static List chars = new ArrayList();
    static {
        char[] charArray = zifu.toCharArray();
        for (char c : charArray) {
            chars.add(c);
        }
    }
    public static String getRandomString(int size){
        Collections.shuffle(chars);
        Random random = new Random();
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < size; i++) {
            int index = random.nextInt(chars.size());
            stringBuffer.append(chars.get(index).toString());
        }
        return stringBuffer.toString();
    }
    public static String getMd5(String source,String salt,int time){
        if (time==1){
            return DigestUtils.md5DigestAsHex((salt+source+salt).getBytes(StandardCharsets.UTF_8));
        }else {
            --time;
            return getMd5(getMd5(source,salt ,1 ),salt,time);
        }
    }
    public static int sum(int max){
        if (max==1){
            return max;
        }
        return max+sum(max-1);
    }
}
